package cn.ren.hai.base.controller;


import cn.ren.hai.base.entity.RhTable;
import cn.ren.hai.base.service.RhTableService;
import cn.ren.hai.core.entity.PageInfo;
import cn.ren.hai.core.entity.QueryPage;
import cn.ren.hai.core.response.ResponseBean;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;

/**
 * <p>
 * 导航  前端控制器
 * </p>
 *
 * @author wangdao
 * @since 2021-06-09
 */
@RestController
@RequestMapping("/api/base/rhTable")
public class RhTableController {


    private final RhTableService rhTableService;

    @Autowired
    public RhTableController(RhTableService rhTableService) {
        this.rhTableService = rhTableService;
    }

    /**
     * 查询分页数据
     */
    @ApiOperation(value = "查询分页数据")
    @PostMapping(value = "/getList")
    public ResponseBean<PageInfo<RhTable>> getList(@RequestBody(required = false) QueryPage<RhTable> page) {
        return new ResponseBean<>(rhTableService.list(page));
    }


    /**
     * 根据id查询
     */
    @ApiOperation(value = "根据id查询数据")
    @GetMapping(value = "/getById")
    public ResponseBean<RhTable> getById(@RequestParam("id") Serializable id) {
        return new ResponseBean<>(rhTableService.getById(id));
    }

    @ApiOperation(value = "查询分页数据")
    @PostMapping(value = "/getByTableName")
    public ResponseBean<RhTable> getByTableName(@RequestBody RhTable rhTable) {

        return new ResponseBean<>(rhTableService.getByTableName(rhTable.getName()));
    }

    /**
     * 新增
     */
    @ApiOperation(value = "新增/修改 数据")
    @PostMapping(value = "/saveUpdate")
    public ResponseBean<Boolean> saveUpdate(@RequestBody RhTable rhTable) {
        return new ResponseBean<>(rhTableService.saveOrUpdate(rhTable));
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除数据")
    @DeleteMapping(value = "/del")
    public ResponseBean<Boolean> delete(@RequestParam("id") Serializable id) {
        return new ResponseBean<>(rhTableService.removeById(id));
    }
}
